package generator.statements;

import generator.addons.SimpleDataGenerator;
import generator.collections.PaymentTable;
import java.sql.Date;

/**
 * Payment SQL record mapper.
 * 
 * @author Necro
 * @author Marek Snopkowski <snpy@snpy.info>
 * @version 12.04.2008
 */
public class Payment extends Statement
{
    private int paymentID;
    
    private Reservation reservation;
    private Date date;
    private float charge;

    public Payment(Reservation reservation, Date date, float charge) 
    {
        this.paymentID   = PaymentTable.autoincrement();        
        this.reservation = reservation;
        this.date        = date;
        this.charge      = charge;
    }
    
    public Object[] getFieldsValueCollection()
    {
        return new Object[]{ paymentID, reservation.getId(), date, charge };
    }
    
    public String getFieldsNameSet()
    {
        return "[payment_id], [reservation_id], [date], [charge]";
    }   
    
    @Override
    public int getId()
    {
        return paymentID;
    }

    public float getCharge()
    {
        return charge;
    }

    public Date getDate()
    {
        return date;
    }
    
    
    public static Payment genRand(Reservation reserv){
        
        Date newDate;
        do { 
             newDate = SimpleDataGenerator.getDate();
        } while (newDate.before(reserv.getReservationDate()));

       return new Payment(reserv, newDate, SimpleDataGenerator.getMoneyTiny());
    }

    @Override
    public String getTableName()
    {
        return "payment";
    }
}
